package com.ldzy.controller;

import com.ldzy.pojo.MyResponse;
import com.ldzy.pojo.ResultCode;
import com.ldzy.pojo.TransferVO;
import com.ldzy.pojo.User;
import com.ldzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("transfer")
    @ResponseBody
    public MyResponse transfer(@RequestBody TransferVO transferVO){
        User inner = transferVO.getInner();
        User outer = transferVO.getOuter();
        Double money = transferVO.getMoney();
        boolean flag = userService.transfer(outer, inner, money);
        if (flag==true){
            MyResponse<Object> myResponse = new MyResponse<>(ResultCode.SUCCESS_TRANSFER);
            return myResponse;
        }else {
            MyResponse<Object> myResponse = new MyResponse<>(ResultCode.ERROR_TRANSFER);
            return myResponse;
        }
    }
}
